﻿using System;
using System.Windows.Forms;

namespace ViewCam
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        #region Properties
        public string title { get; set; }
        public Form mainForm { get; set; }
        public Int32 AutoNotifyStop { get; set; }
        public Int32 AutoRecordStop { get; set; }
        public Int32 BeepDura { get; set; }
        public Int32 BeepFreq { get; set; }
        public string RecordPath { get; set; }
        #endregion

        #region Declarations
        ViewCamHelper viewcamModule;
        CameraIPForm camIPform;
        #endregion

        #region Controls

        /// <summary>
        /// Handles the Load event of the LoginForm control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void LoginForm_Load(object sender, EventArgs e)
        {
            this.Text = title;
            SetTheme();
        }

        /// <summary>
        /// Handles the Click event of the btnCancel control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// Handles the Click event of the btnEnter control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void btnEnter_Click(object sender, EventArgs e)
        {
            if (CheckForNull())
            {
                camIPform = new CameraIPForm();
                camIPform.MdiParent = mainForm;
                camIPform.title = txtURL.Text;
                camIPform.url = txtURL.Text;
                camIPform.username = txtUsername.Text;
                camIPform.password = txtPassword.Text;
                camIPform.type = cmbType.Text;
                camIPform.RecordPath = RecordPath;
                camIPform.AutoNotifyStop = AutoNotifyStop;
                camIPform.AutoRecordStop = AutoRecordStop;
                camIPform.BeepDura = BeepDura;
                camIPform.BeepFreq = BeepFreq;
                camIPform.Show();

                this.Close();
            }
            else
            {
                MessageBox.Show("Login Credentials Incorrect/Incomplete. Please try again.", "View Cam");
            }

        }

        #endregion

        #region Methods

        /// <summary>
        /// Sets the theme.
        /// </summary>
        private void SetTheme()
        {
            viewcamModule = new ViewCamHelper();
            this.BackColor = viewcamModule.SetThemeColor(lblStatus);
        }

        /// <summary>
        /// Checks for null.
        /// </summary>
        /// <returns></returns>
        private bool CheckForNull()
        {
            bool boolChecker = false;

            if (txtURL.Text != "" & cmbType.Text != "")
            {
                boolChecker = true;
            }

            return boolChecker;
        }
        #endregion

    }
}
